#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char **argv) {

	int size = 100;
	// ler 100c de cada vez
	char * buffer = (char *) malloc(sizeof(char) * size);

	/* Display 10 numbers. */

	int random = (rand() % 1000) * getpid() % 10;
	printf("[%d] Gonna read %d lines\n", getpid(), random);

	int n_bytesRead = 0;
	int count = 0;
	while (count < random) {
		count++;
		n_bytesRead = read(STDIN_FILENO, buffer, size);
		printf("[%d]| %s\n", getpid(), buffer);
		if (n_bytesRead == -1) {
			perror("read");
			exit(EXIT_FAILURE);
		}
	};
	printf("[%d] termnou\n", getpid());

}
